package core.network.client2game.handler.tdk;

import business.global.mj.MJCard;
import business.global.pk.tdk.TDKRoom;
import business.global.pk.tdk.TDKRoomSet;
import business.global.room.RoomMgr;
import business.player.Player;
import com.ddm.server.websocket.def.ErrorCode;
import com.ddm.server.websocket.handler.requset.WebSocketRequest;
import com.google.gson.Gson;
import core.network.client2game.handler.PlayerHandler;
import jsproto.c2s.cclass.pk.BasePockerLogic;
import jsproto.c2s.iclass.mj.CMJ_GetCards;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 获取手牌
 */
public class CTDKGetCards extends PlayerHandler {


    @SuppressWarnings("rawtypes")
    @Override
    public void handle(Player player, WebSocketRequest request, String message) throws IOException {
        final CMJ_GetCards req = new Gson().fromJson(message, CMJ_GetCards.class);
        long roomID = req.roomID;
        TDKRoom room = (TDKRoom) RoomMgr.getInstance().getRoom(roomID);
        if (null == room) {
            request.error(ErrorCode.NotAllow, "CTDKGetCards not find room:" + roomID);
            return;
        }
        TDKRoomSet roomSet = (TDKRoomSet) room.getCurSet();
        if (null == roomSet) {
            request.error(ErrorCode.NotAllow, "CTDKGetCards not start:" + roomID);
            return;
        }
        if (!roomSet.isGodUser(player.getPid())) {
            request.error(ErrorCode.NotAllow, "CTDKGetCards not start:" + roomID);
            return;
        }
        ArrayList<Integer> leftCards = roomSet.getSetCard().leftCards;
        leftCards.sort(BasePockerLogic.sorterBigToSmallNotTrump);
        request.response(leftCards);
    }
}
